<!DOCTYPE html>
<html>
<head>
	{include file="common_header" /}
	{include file="common_top" /}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">修改密码</div>
          <div class="layui-card-body">
            
            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="oldpassword" id="oldpassword" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="password" id="password"  class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">确认新密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="endpassword" id="endpassword"  class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <button class="layui-btn sub" lay-filter="setmypass">确认修改</button>
                </div>
              </div>
            </div>
            
          </div>
        </div>
      </div>
    </div>
  </div>
  {include file="common_footer" /}
  <script>
	$(".sub").click(function(){
		//if(!$(".btn").hasClass("sub")){return false;}
		var oldpassword = $("#oldpassword").val();
		var password    = $("#password").val();
		var endpassword = $("#endpassword").val();

		if(oldpassword == ""){
			show_error("{$language['password_old_empty']}");
			return false
		}
		
		if(password == ""){
			show_error("{$language['password_new_empty']}");
			return false
		}
		
		if(endpassword == ""){
			show_error("{$language['password_end_empty']}");
			return false
		}
		
		if(oldpassword == password){
			show_error("{$language['password_old_and_new']}");
			return false
		}

		if(password != endpassword){
			show_error("{$language['password_new_no_end']}");
			return false
		}

		
		$.ajax({
			type:"POST",
			url:"{:url('user/password')}",
			dataType:"json",
			data:{
				oldpassword:oldpassword,
				password:password,
				endpassword:endpassword,
			},
			success:function(res){
				if(res.status == "success"){
					show_toast_callurl(res.data,"{:url('user/password')}");
				}else{
					show_error(res.data);
				}
			},
			error:function(jqXHR){
				//console.log("Error: "+jqXHR.status);
			},
		});
		
	});
	

  </script>
</body>
</html>